using System;
using System.Windows;
namespace Microsoft.Phone.Controls
{
	public static class ContextMenuService
	{
		public static readonly DependencyProperty ContextMenuProperty = DependencyProperty.RegisterAttached("ContextMenu", typeof(ContextMenu), typeof(ContextMenuService), new PropertyMetadata(null, new PropertyChangedCallback(ContextMenuService.OnContextMenuChanged)));
		public static ContextMenu GetContextMenu(DependencyObject element)
		{
			if (element == null)
			{
				throw new ArgumentNullException("element");
			}
			return (ContextMenu)element.GetValue(ContextMenuService.ContextMenuProperty);
		}
		public static void SetContextMenu(DependencyObject element, ContextMenu value)
		{
			if (element == null)
			{
				throw new ArgumentNullException("element");
			}
			element.SetValue(ContextMenuService.ContextMenuProperty, value);
		}
		private static void OnContextMenuChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
		{
			FrameworkElement frameworkElement = o as FrameworkElement;
			if (frameworkElement != null)
			{
				ContextMenu contextMenu = e.get_OldValue() as ContextMenu;
				if (contextMenu != null)
				{
					contextMenu.Owner = null;
				}
				ContextMenu contextMenu2 = e.get_NewValue() as ContextMenu;
				if (contextMenu2 != null)
				{
					contextMenu2.Owner = frameworkElement;
				}
			}
		}
	}
}
